﻿namespace A2DFramework.OSGI.ConnectionChannel
{
    using A2DFramework.OSGI.BundleContexts;
    using System;

    internal class OSGICommunicatorImpl : MarshalByRefObject, IOSGICommunicator
    {
        private Random rdn = new Random();

        public void CloseService(string requestServiceType)
        {
            throw new NotImplementedException();
        }

        public RemoteServiceDto OpenService(string requestServiceType)
        {
            int prot = this.rdn.Next(0xfa0, 0x1770);
            string serviceUri = Guid.NewGuid().ToString("N");
            BundleContext.Current.RegisterOSGIService(requestServiceType, prot, serviceUri);
            return new RemoteServiceDto { Port = prot, ServiceUri = serviceUri };
        }
    }
}

